package com.example.hxds.cst.service.impl;

import com.codingapi.txlcn.tc.annotation.LcnTransaction;
import com.example.hxds.cst.db.dao.CustomerCarDao;
import com.example.hxds.cst.db.pojo.CustomerCarEntity;
import com.example.hxds.cst.service.CustomerCarService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * @ClassName: CustomerCarServiceImpl
 * @Description: 客户车辆服务实现
 * @Author: 丛雨
 * @Date: 2024/1/27 18:57
 */
@Service
@Slf4j
public class CustomerCarServiceImpl implements CustomerCarService {
    @Resource
    private CustomerCarDao customerCarDao;

    /**
     * 新增客户车辆
     *
     * @param entity 车辆信息,含车牌,车型,客户Id
     */
    @Override
    @Transactional
    @LcnTransaction
    public void insertCustomerCar(CustomerCarEntity entity) {
        customerCarDao.insert(entity);
    }

    /**
     * 查询客户车辆列表
     *
     * @param customerId 客户Id
     * @return 查询结果
     */
    @Override
    public ArrayList<HashMap> searchCustomerCarList(long customerId) {
        ArrayList<HashMap> carList = customerCarDao.searchCustomerCarList(customerId);
        return carList;
    }

    /**
     * 删除客户车辆
     *
     * @param id 车辆Id
     * @return 删除结果
     */
    @Override
    @Transactional
    @LcnTransaction
    public int deleteCustomerCarById(long id) {
        int rows = customerCarDao.deleteCustomerCarById(id);
        return rows;
    }
}
